--酣醉之夜
local hanzuizhiye = fk.CreateSkill {
    name = "mcdh_hanzuizhiye",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

hanzuizhiye:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and target.phase == Player.Start
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        if target == player then
            return room:askForSkillInvoke(player,self.name)
        else
            local  card =room:askForDiscard(player, 2, 2, true, self.name, true, ".", "#hanzuizhiye-discard")
            if #card == 2 then
                self.cost_data = card
                return true
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room =player.room
        if target ~= player then
            room:throwCard(self.cost_data,self.name,player,player)
        end
        player:drawCards(1, self.name)
        local card = room:askForCard(player,1,1,true,self.name,false,".","#hanzuizhiye-show")
        player:showCards(card)
        local mark = {}
        table.insert(mark,Fk:getCardById(card[1]):getColorString())
        for _,p in ipairs(room:getAlivePlayers()) do
            room:setPlayerMark(p, "@mcdh_hanzuizhiye-turn",mark)
        end
    end,
})

hanzuizhiye:addEffect(fk.CardUseFinished,{
    can_refresh = function(self, event, target, player, data)
        return  data.card.name == "analeptic"
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        for _,p in ipairs(room:getAlivePlayers()) do
            room:setPlayerMark(p, "@mcdh_hanzuizhiye-turn",0)
        end
    end,
})

hanzuizhiye:addEffect('filter',{
    card_filter = function(self, card, player)
        return table.contains(player:getTableMark("@mcdh_hanzuizhiye-turn"),card:getColorString()) and
                table.contains(player.player_cards[Player.Hand], card.id)
    end,
    view_as = function(self, card)
        local c = Fk:cloneCard("analeptic", card.suit, card.number)
        c.skillName = self.name
        return c
    end
})

Fk:loadTranslationTable{
    ["mcdh_hanzuizhiye"] ="酣醉之夜",
    ["#hanzuizhiye-show"] = "酣醉之夜:展示一张牌",
    [":mcdh_hanzuizhiye"]="准备阶段,你可以摸一张牌，然后展示一张牌且本回合内:所有角色手牌中与此展示牌颜色相同的牌视为【酒】,直到本回合有【酒】结算完毕。其他角色的准备阶段,你可以弃置两张牌,然后发动本技能。",
    ["#mcdh_hanzuizhiye_filter"] = "酣醉之夜",
    ["@mcdh_hanzuizhiye-turn"] = "酣醉之夜",
    ["#hanzuizhiye-discard"] = "酣醉之夜:弃置两张牌,然后发动 酣醉之夜。"
}

return hanzuizhiye